package com.rbc.rlsplips.servicemanager.impl;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.xml.namespace.QName;
import javax.xml.ws.Binding;
import javax.xml.ws.BindingProvider;

import org.apache.log4j.Logger;

import ca.qc.gouv.mrq.t1a._04111900.annuaire.AnnuaireLogiciel;
import ca.qc.gouv.mrq.t1a._04111900.annuaire.AnnuaireLogicielSoap;
import ca.qc.gouv.mrq.t1a._04111900.annuaire.ArrayOfObtenirUrlServiceIN;
import ca.qc.gouv.mrq.t1a._04111900.annuaire.ArrayOfObtenirUrlServiceOUT;

import com.rbc.rlslips.ServiceManager.ServiceManager;
import com.rbc.rlslips.enums.PropertiesKeysEnum;
import com.rbc.rlslips.logger.RLLogger;
import com.rbc.rlslips.object.builder.ObjectBuilder;
import com.rbc.rlslips.properties.manager.PropertiesReader;
import com.rbc.rlsplips.saop.handlers.Handler;
import com.sun.xml.internal.ws.developer.WSBindingProvider;

public class AnnuaireLogicielServiceImpl implements ServiceManager<AnnuaireLogicielSoap,ArrayOfObtenirUrlServiceIN,ArrayOfObtenirUrlServiceOUT>{

	private AnnuaireLogicielSoap annuaireLogicielSoap;
	
	private ArrayOfObtenirUrlServiceIN arrayOfObtenirUrlServiceIN;
	
	private Logger logger = Logger.getLogger(AnnuaireLogicielServiceImpl.class);
	
	public AnnuaireLogicielServiceImpl(URL url,QName qName){
		RLLogger.info(logger,"Entered AnnuaireLogicielServiceImpl constructor", url,qName);
		buildRequest(url, qName);
		setBindingProperties();
		RLLogger.info(logger,"Exited AnnuaireLogicielServiceImpl constructor");
	}
	
	public AnnuaireLogicielServiceImpl(){
		
	}
	@Override
	public ArrayOfObtenirUrlServiceIN buildRequest(URL url,QName qName) {
		// TODO Auto-generated method stub
		RLLogger.info(logger,"Entered buildRequest of <AnnuaireLogicielServiceImpl>", url,qName);
		AnnuaireLogiciel annuaireLogiciel=new AnnuaireLogiciel(url,qName);
		this.annuaireLogicielSoap = annuaireLogiciel.getAnnuaireLogicielSoap();
		this.arrayOfObtenirUrlServiceIN = ObjectBuilder.buildArrayOfObtenirUrlServiceIN();
		RLLogger.info(logger,"Exited buildRequest of <AnnuaireLogicielServiceImpl>", url,qName);
		return null;
	}

	@Override
	public ArrayOfObtenirUrlServiceOUT invokeService() {
		// TODO Auto-generated method stub
		return this.annuaireLogicielSoap.obtenirUrlsServices(this.arrayOfObtenirUrlServiceIN);
		
	}

	@Override
	public void processResponse(ArrayOfObtenirUrlServiceOUT response) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setBindingProperties() {
		RLLogger.info(logger,"Entered AnnuaireLogicielServiceImpl constructor");
		WSBindingProvider bindProv=(WSBindingProvider) this.annuaireLogicielSoap;
		Binding binding = bindProv.getBinding();
		List handlerList = binding.getHandlerChain();
		if (handlerList == null) {
		handlerList = new ArrayList();
		}
		handlerList.add(new Handler());
		binding.setHandlerChain(handlerList);
		bindProv.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,PropertiesReader.getProperty(PropertiesKeysEnum.END_POINT_KEY));
		bindProv.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,PropertiesReader.getProperty(PropertiesKeysEnum.BIND_USER_NAME_KEY));
		bindProv.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,PropertiesReader.getProperty(PropertiesKeysEnum.BIND_PASSWORD_KEY));
		RLLogger.info(logger,"Exited AnnuaireLogicielServiceImpl constructor");
	}

	

	

}
